geom_point(aes(x=year, y=elec_quality)) +
geom_smooth(aes(x=year, y=elec_quality), method="lm", se = F) +
xlab("") +
ylab("Election fraud") +
theme_classic() +
theme(plot.margin = unit(c(1,1,1,1), "cm"))
## line plot of percentage of countreis reported fraud over years
elecQuality_perc = ggplot(vdem_perc) +
geom_point(aes(x=year, y=perc)) +
geom_smooth(aes(x=year, y=perc), method="lm", se = F, color = "palegreen4", alpha = 0.5) +
geom_smooth(aes(x=year, y=perc), method="loess", se = F, color = "plum4", alpha = 0.5) +
xlab("") +
ylab("Average election fraud score") +
theme_classic() +
theme(plot.margin = unit(c(1,1,1,1), "cm"))
pdf("../Results/Figures/SI-FigureI4.pdf", width = 10, height = 4, onefile = TRUE)
grid.arrange(elecQuality_scatter, elecQuality_perc, nrow=1,ncol=2)
dev.off()
##################################################################################################
##################################################################################################
# The following part generates all the tables in the paper and SI with
# units of analysis being country - election type - election year
#################################################
###########         Run Models        ###########
#################################################
# Read dataset
didData_year = read_csv("../Data/mainData_yearly.csv") %>% mutate(cowcode = factor(cowcode))
didData_year = panel(didData_year, ~ country_election + year)
# Set variables
# Independent variables
vecIV = c('log_nlevel','policy_down_level', 'policy_down_u_std', 'policy_down_u_50p',"policy_down_u_g2")
# Dependent variables
vecDV = c('other_irreg','pei_faircount',"registry_irreg","pei_delay",'govt_intimidation',"nelda15","nelda33",
'v2xnp_client','elec_quality','fraud_monitored','nelda29',
"freefair","opposition_prevented_nelda13","campaign_media",
"domestic_monitors","inter_monitors","pei_laws","pei_procedures","incumbent_vote_share")
# Control variables
vecControls = c('l_le_wb_pop', 'lv2elembaut', 'lv2elembcap', 'le_polity2', 'l_lgdp_c15', 'lurban', 'ltotalseats', 'lnelda45')
# Set models
## Plain FE
did_str_FE = paste0("outcome ~ treatment + ", paste0(vecControls, collapse = " + "), " | factor(country_election)")
## Plain TWFE
did_str_TWFE = paste0("outcome ~ treatment + ", paste0(vecControls, collapse = " + "), " | factor(country_election) + factor(year)")
vecModels = c(did_str_FE, did_str_TWFE)
#####################################################################
# Get all the model specifications
model_specs_main = expand.grid(outcome = vecDV, treatment = vecIV,
model_spec = vecModels,stringsAsFactors = FALSE)
model_specs_main = model_specs_main %>%
mutate(model_spec_type = case_when(
model_specs_main$model_spec==did_str_FE~"Simple FE",
model_specs_main$model_spec==did_str_TWFE~"TWFE")) %>%
mutate(treatment = factor(treatment, levels = vecIV, labels = vecIV)) %>%
mutate(outcome = factor(outcome, levels = vecDV, labels = vecDV)) %>%
arrange(outcome,treatment)
# Run all models
run_all_models = list()
for(i in 1:nrow(model_specs_main)){
## select outcome
outcome = model_specs_main$outcome[i]
treatment = model_specs_main$treatment[i]
model_spec = model_specs_main$model_spec[i]
model_spec_type = model_specs_main$model_spec_type[i]
modelData = didData_year
modelData$outcome = didData_year %>% pull(outcome)
modelData$treatment = didData_year %>% pull(treatment)
model_out = feols(as.formula(model_spec), data = modelData,cluster = ~country_name)
run_all_models[[i]] = model_out}
cm = c("treatment" = "Granularity")
#####################################################################
# Run model for NELDA 24 variable separately
# restrict sample to be only those observations with well-defined incumbents
presData_year = didData_year %>% filter(!is.na(incumbent_vote_share))
vecDV = c('nelda24')
model_specs_nelda24 = expand.grid(
outcome = vecDV,
treatment = vecIV,
model_spec = vecModels,
stringsAsFactors = FALSE)
model_specs_nelda24 = model_specs_nelda24 %>%
mutate(model_spec_type = case_when(model_specs_nelda24$model_spec==did_str_FE~"Simple FE",model_specs_nelda24$model_spec==did_str_TWFE~"TWFE")) %>%
mutate(treatment = factor(treatment, levels = vecIV, labels = vecIV)) %>%
mutate(outcome = factor(outcome, levels = vecDV, labels = vecDV)) %>%
arrange(outcome,treatment)
run_all_models_nelda24 = list()
for(i in 1:nrow(model_specs_nelda24)){
## select outcome
outcome = model_specs_nelda24$outcome[i]
treatment = model_specs_nelda24$treatment[i]
model_spec = model_specs_nelda24$model_spec[i]
model_spec_type = model_specs_nelda24$model_spec_type[i]
modelData = presData_year
modelData$outcome = presData_year %>% pull(outcome)
modelData$treatment = presData_year %>% pull(treatment)
model_out = feols(as.formula(model_spec),data = modelData,cluster = ~country_name)
run_all_models_nelda24[[i]] = model_out}
######################################################
###########          SI-Table H1           ###########
######################################################
## Get the country-election list then manually check each entry
presList = didData_year %>% filter(policy_down_level == 1, election_type=="Presidential") %>% pull(country_name) %>% unique()
presData = didData_year %>% as.data.frame() %>%
filter(election_type=="Presidential", country_name %in% presList) %>%
select(country_name, year, election_type, unit_level, name_english_, nlevel,policy_down_level) %>%
group_by(country_name) %>%
mutate(lag.unit_level = dplyr::lag(unit_level, n = 1, default = NA),
lag.name_english_ = dplyr::lag(name_english_, n = 1, default = NA),
lag.nlevel = dplyr::lag(nlevel, n = 1, default = NA)) %>%
ungroup() %>% filter(policy_down_level == 1, unit_level != lag.unit_level) %>%
mutate(change_units = (nlevel - lag.nlevel)/lag.nlevel) %>%
select(country_name,year,election_type, lag.name_english_,name_english_,
lag.unit_level,unit_level,lag.nlevel,nlevel,change_units) %>%
rename(`Unit Name Before` = lag.name_english_, `Unit Name After` = name_english_,
`Unit Level Before` = lag.unit_level, `Unit Level After` = unit_level,
`Units Before` = lag.nlevel, `Units After` = nlevel,
`Country Name` = country_name, Year = year, `Election Type` = election_type,
`Change in Units (%)` = change_units)
presData |>
select(-c(`Unit Level Before`,`Unit Level After`)) |>
mutate(`Change in Units (%)` = round(`Change in Units (%)`, 2)) |>
mutate(`Unit Name Before` = stringr::str_to_title(`Unit Name Before`),
`Unit Name After` = stringr::str_to_title(`Unit Name After`),
`Country Name` = stringr::str_to_title(`Country Name`)) |>
write_csv(file = "../Results/Tables/SI-TableH1.csv")
######################################################
###########          SI-Table H2           ###########
######################################################
parlList = didData_year %>% filter(policy_down_level == 1, election_type=="Legislative") %>% pull(country_name) %>% unique()
parlData = didData_year %>% as.data.frame() %>%
filter(election_type=="Legislative", country_name %in% parlList) %>%
select(country_name, year, election_type, unit_level, name_english_, nlevel,policy_down_level) %>%
group_by(country_name) %>%
mutate(lag.unit_level = dplyr::lag(unit_level, n = 1, default = NA),
lag.name_english_ = dplyr::lag(name_english_, n = 1, default = NA),
lag.nlevel = dplyr::lag(nlevel, n = 1, default = NA)) %>%
ungroup() %>% filter(policy_down_level == 1, unit_level != lag.unit_level) %>%
mutate(change_units = (nlevel - lag.nlevel)/lag.nlevel) %>%
filter(change_units>=0) %>%
select(country_name,year,election_type, lag.name_english_,name_english_,
lag.unit_level,unit_level,lag.nlevel,nlevel,change_units) %>%
rename(`Unit Name Before` = lag.name_english_, `Unit Name After` = name_english_,
`Unit Level Before` = lag.unit_level, `Unit Level After` = unit_level,
`Units Before` = lag.nlevel, `Units After` = nlevel,
`Country Name` = country_name, Year = year, `Election Type` = election_type,
`Change in Units (%)` = change_units)
parlData |>
select(-c(`Unit Level Before`,`Unit Level After`)) |>
mutate(`Change in Units (%)` = round(`Change in Units (%)`, 2)) |>
mutate(`Unit Name Before` = stringr::str_to_title(`Unit Name Before`),
`Unit Name After` = stringr::str_to_title(`Unit Name After`),
`Country Name` = stringr::str_to_title(`Country Name`)) |>
write_csv(file = "../Results/Tables/SI-TableH2.csv")
####################################################
###########          SI-Table J9         ###########
####################################################
inds1 = which(model_specs_main$outcome %in% c("other_irreg") &
model_specs_main$treatment %in% c('log_nlevel', 'policy_down_level', 'policy_down_u_std') &
model_specs_main$model_spec_type == "Simple FE")
inds3 = which(model_specs_main$outcome %in% c("pei_faircount") &
model_specs_main$treatment %in% c('log_nlevel','policy_down_level', 'policy_down_u_std') &
model_specs_main$model_spec_type == "Simple FE")
inds = c(inds1, inds3)
model1 = didData_year %>% as.data.frame() %>% drop_na('other_irreg',"log_nlevel", vecControls)
model2 = didData_year %>% as.data.frame() %>% drop_na('other_irreg',"policy_down_level", vecControls)
model3 = didData_year %>% as.data.frame() %>% drop_na('other_irreg',"policy_down_u_std", vecControls)
model4 = didData_year %>% as.data.frame() %>% drop_na('pei_faircount',"log_nlevel", vecControls)
model5 = didData_year %>% as.data.frame() %>% drop_na('pei_faircount',"policy_down_level", vecControls)
model6 = didData_year %>% as.data.frame() %>% drop_na('pei_faircount',"policy_down_u_std", vecControls)
vecCoefs = c()
vecCE = c() ## How many country-election
vecPeriod = c() ## How many period
for (i in inds){
mod = run_all_models[[i]]
estimate = broom::tidy(mod)%>%filter(term %in% c("treatment"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))}
rows <- tibble::tribble(~term,   ~"(1)",  ~"(2)",  ~"(3)",  ~"(4)",  ~"(5)",  ~"(6)",
"Country-Election FE", "Yes","Yes","Yes","Yes","Yes","Yes",
"Granularity Est./Mean", as.character(round(vecCoefs[1]/(model1%>% pull(other_irreg) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[2]/(model2%>% pull(other_irreg) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[3]/(model3%>% pull(other_irreg) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[4]/(model4%>% pull(pei_faircount) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[5]/(model5%>% pull(pei_faircount) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[6]/(model6%>% pull(pei_faircount) %>% mean() %>% abs()),2)),
"No. Countries",as.character(length(unique(model1$country_name))),as.character(length(unique(model2$country_name))),as.character(length(unique(model3$country_name))),as.character(length(unique(model4$country_name))),as.character(length(unique(model5$country_name))),as.character(length(unique(model6$country_name))),
"No. Country-Elections", vecCE[1],vecCE[2], vecCE[3],   vecCE[4], vecCE[5], vecCE[6])
attr(rows, 'position') <- c(3, 4, 5, 6, 7, 8)
modelsummary(run_all_models[inds],
col.names = c("","(1)","(2)","(3)","(4)","(5)","(6)"),
fmt = "%.3f",
estimate = "{estimate}{stars}",
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_map = gm,
add_rows = rows,
output = "latex",
coef_map = cm) %>%
save_tt(output = "../Results/Tables/SI-TableJ9.tex", overwrite = TRUE)
####################################################
###########    SI-Table J10 Panel A      ###########
####################################################
## Panel A:
indsA = c()
for (out in c('nelda33',"v2xnp_client",'govt_intimidation', "opposition_prevented_nelda13", "campaign_media")){
inds1 = which(model_specs_main$outcome == out &
model_specs_main$treatment %in% c('log_nlevel','policy_down_level') &
model_specs_main$model_spec_type %in% c("Simple FE"))
indsA = c(indsA, inds1)}
## Calculate effect size
model1 = didData_year %>% as.data.frame() %>% drop_na("nelda33",'log_nlevel', vecControls)
model3 = didData_year %>% as.data.frame() %>% drop_na("v2xnp_client",'log_nlevel', vecControls)
model5 = didData_year %>% as.data.frame() %>% drop_na("govt_intimidation",'log_nlevel', vecControls)
model7 = didData_year %>% as.data.frame() %>% drop_na("opposition_prevented_nelda13",'log_nlevel', vecControls)
model9 = didData_year %>% as.data.frame() %>% drop_na("campaign_media",'log_nlevel', vecControls)
model2 = didData_year %>% as.data.frame() %>% drop_na("nelda33", "policy_down_level",vecControls)
model4 = didData_year %>% as.data.frame() %>% drop_na("v2xnp_client", "policy_down_level",vecControls)
model6 = didData_year %>% as.data.frame() %>% drop_na("govt_intimidation","policy_down_level", vecControls)
model8 = didData_year %>% as.data.frame() %>% drop_na("opposition_prevented_nelda13", "policy_down_level",vecControls)
model10 = didData_year %>% as.data.frame() %>% drop_na("campaign_media", "policy_down_level",vecControls)
vecCoefs = c()
vecCE = c() ## How many country-election
for (i in indsA){
mod = run_all_models[[i]]
estimate = broom::tidy(mod)%>%filter(term %in% c("treatment"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))
}
rows <- tibble::tribble(~term,   ~"(1)",  ~"(2)",  ~"(3)",  ~"(4)",  ~"(5)",  ~"(6)", ~"(7)",  ~"(8)",  ~"(9)",  ~"(10)",
"Country-Election FE", "Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes",
"Granularity Est./Mean",
as.character(round(vecCoefs[1]/(model1%>% pull(nelda33) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[2]/(model2%>% pull(nelda33) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[3]/(model3%>% pull(v2xnp_client) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[4]/(model4%>% pull(v2xnp_client) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[5]/(model5%>% pull(govt_intimidation) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[6]/(model6%>% pull(govt_intimidation) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[7]/(model7%>% pull(opposition_prevented_nelda13) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[8]/(model8%>% pull(opposition_prevented_nelda13) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[9]/(model9%>% pull(campaign_media) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[10]/(model10%>% pull(campaign_media) %>% mean() %>% abs()),2)),
"No. Countries",
as.character(length(unique(model1$country_name))),
as.character(length(unique(model2$country_name))),
as.character(length(unique(model3$country_name))),
as.character(length(unique(model4$country_name))),
as.character(length(unique(model5$country_name))),
as.character(length(unique(model6$country_name))),
as.character(length(unique(model7$country_name))),
as.character(length(unique(model8$country_name))),
as.character(length(unique(model9$country_name))),
as.character(length(unique(model10$country_name))),
"No. Country-Elections", vecCE[1],vecCE[2], vecCE[3], vecCE[4], vecCE[5], vecCE[6], vecCE[7],vecCE[8], vecCE[9], vecCE[10])
attr(rows, 'position') <- c(3, 4, 5, 6, 7, 8)
modelsummary(run_all_models[indsA],
col.names = c("","(1)","(2)","(3)","(4)","(5)","(6)","(7)","(8)","(9)","(10)"),
fmt = "%.3f",
estimate = "{estimate}{stars}",
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_map = gm,
add_rows = rows,
output = "latex",
coef_map = cm) %>%
save_tt(output = "../Results/Tables/SI-TableJ10-panelA.tex", overwrite = TRUE)
####################################################
###########    SI-Table J10 Panel B      ###########
####################################################
## Panel B:
indsB = c()
for (out in c('domestic_monitors',"inter_monitors",'registry_irreg', "pei_laws", "pei_procedures")){
inds1 = which(model_specs_main$outcome == out &
model_specs_main$treatment %in% c('log_nlevel','policy_down_level') &
model_specs_main$model_spec_type %in% c("Simple FE"))
indsB = c(indsB, inds1)
}
## Calculate effect size
model1 = didData_year %>% as.data.frame() %>% drop_na("domestic_monitors",'log_nlevel', vecControls)
model3 = didData_year %>% as.data.frame() %>% drop_na("inter_monitors",'log_nlevel', vecControls)
model5 = didData_year %>% as.data.frame() %>% drop_na("registry_irreg",'log_nlevel', vecControls)
model7 = didData_year %>% as.data.frame() %>% drop_na("pei_laws",'log_nlevel', vecControls)
model9 = didData_year %>% as.data.frame() %>% drop_na("pei_procedures",'log_nlevel', vecControls)
model2 = didData_year %>% as.data.frame() %>% drop_na("domestic_monitors", "policy_down_level",vecControls)
model4 = didData_year %>% as.data.frame() %>% drop_na("inter_monitors", "policy_down_level",vecControls)
model6 = didData_year %>% as.data.frame() %>% drop_na("registry_irreg","policy_down_level", vecControls)
model8 = didData_year %>% as.data.frame() %>% drop_na("pei_laws", "policy_down_level",vecControls)
model10 = didData_year %>% as.data.frame() %>% drop_na("pei_procedures", "policy_down_level",vecControls)
vecCoefs = c()
vecCE = c() ## How many country-election
for (i in indsB){
mod = run_all_models[[i]]
estimate = broom::tidy(mod)%>%filter(term %in% c("treatment"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))
}
rows <- tibble::tribble(~term,   ~"(1)",  ~"(2)",  ~"(3)",  ~"(4)",  ~"(5)",  ~"(6)", ~"(7)",  ~"(8)",  ~"(9)",  ~"(10)",
"Country-Election FE", "Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes",
"Granularity Est./Mean",
as.character(round(vecCoefs[1]/(model1%>% pull(domestic_monitors) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[2]/(model2%>% pull(domestic_monitors) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[3]/(model3%>% pull(inter_monitors) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[4]/(model4%>% pull(inter_monitors) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[5]/(model5%>% pull(registry_irreg) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[6]/(model6%>% pull(registry_irreg) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[7]/(model7%>% pull(pei_laws) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[8]/(model8%>% pull(pei_laws) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[9]/(model9%>% pull(pei_procedures) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[10]/(model10%>% pull(pei_procedures) %>% mean() %>% abs()),2)),
"No. Countries",
as.character(length(unique(model1$country_name))),
as.character(length(unique(model2$country_name))),
as.character(length(unique(model3$country_name))),
as.character(length(unique(model4$country_name))),
as.character(length(unique(model5$country_name))),
as.character(length(unique(model6$country_name))),
as.character(length(unique(model7$country_name))),
as.character(length(unique(model8$country_name))),
as.character(length(unique(model9$country_name))),
as.character(length(unique(model10$country_name))),
"No. Country-Elections", vecCE[1],vecCE[2], vecCE[3], vecCE[4], vecCE[5], vecCE[6], vecCE[7],vecCE[8], vecCE[9], vecCE[10])
attr(rows, 'position') <- c(3, 4, 5, 6, 7, 8)
modelsummary(run_all_models[indsB],
col.names = c("","(1)","(2)","(3)","(4)","(5)","(6)","(7)","(8)","(9)","(10)"),
fmt = "%.3f",
estimate = "{estimate}{stars}",
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_map = gm,
add_rows = rows,
output = "latex",
coef_map = cm) %>%
save_tt(output = "../Results/Tables/SI-TableJ10-panelB.tex", overwrite = TRUE)
####################################################
###########    SI-Table J11 Panel A      ###########
####################################################
inds = c()
for (out in c('elec_quality','fraud_monitored')){
inds1 = which(model_specs_main$outcome == out &
model_specs_main$treatment %in% c('log_nlevel','policy_down_level', 'policy_down_u_std') &
model_specs_main$model_spec_type %in% c("Simple FE"))
inds = c(inds, inds1)}
model1 = didData_year %>% as.data.frame() %>% drop_na("elec_quality","log_nlevel", vecControls)
model4 = didData_year %>% as.data.frame() %>% drop_na("fraud_monitored","log_nlevel", vecControls)
model2 = didData_year %>% as.data.frame() %>% drop_na("elec_quality","policy_down_level", vecControls)
model5 = didData_year %>% as.data.frame() %>% drop_na("fraud_monitored","policy_down_level", vecControls)
model3 = didData_year %>% as.data.frame() %>% drop_na("elec_quality","policy_down_u_std", vecControls)
model6 = didData_year %>% as.data.frame() %>% drop_na("fraud_monitored","policy_down_u_std", vecControls)
vecCoefs = c()
vecCE = c() ## How many country-election
for (i in inds){
mod = run_all_models[[i]]
estimate = tidy(mod)%>%filter(term %in% c("treatment","stacktreat"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))}
rows <- tibble::tribble(~term,   ~"(1)",  ~"(2)",  ~"(3)",  ~"(4)",  ~"(5)",  ~"(6)",
"Country-Election FE", "Yes","Yes","Yes","Yes","Yes","Yes",
"Granularity Est./Mean",
as.character(round(vecCoefs[1]/(model1%>% pull(elec_quality) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[2]/(model2%>% pull(elec_quality) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[3]/(model3%>% pull(elec_quality) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[4]/(model4%>% pull(fraud_monitored) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[5]/(model5%>% pull(fraud_monitored) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[6]/(model6%>% pull(fraud_monitored) %>% mean() %>% abs()),2)),
"No. Countries",as.character(length(unique(model1$country_name))),as.character(length(unique(model2$country_name))),as.character(length(unique(model3$country_name))),as.character(length(unique(model4$country_name))),as.character(length(unique(model5$country_name))),as.character(length(unique(model6$country_name))),
"No. Country-Elections", vecCE[1], vecCE[2], vecCE[3],  vecCE[4], vecCE[5], vecCE[6])
attr(rows, 'position') <- c(3, 4, 5, 6, 7, 8)
modelsummary(run_all_models[inds],
col.names = c("","(1)","(2)","(3)","(4)","(5)","(6)"),
fmt = "%.3f",
estimate = "{estimate}{stars}",
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_map = gm,
add_rows = rows,
output = "latex",
coef_map = cm,
notes = "") %>%
save_tt(output = "../Results/Tables/SI-TableJ11-panelA.tex", overwrite = TRUE)
####################################################
###########    SI-Table J11 Panel B      ###########
####################################################
inds = c()
for (out in c('freefair','nelda29')){
inds1 = which(model_specs_main$outcome == out &
model_specs_main$treatment %in% c('log_nlevel','policy_down_level', 'policy_down_u_std') &
model_specs_main$model_spec_type %in% c("Simple FE"))
inds = c(inds, inds1)}
model1 = didData_year %>% as.data.frame() %>% drop_na("freefair","log_nlevel", vecControls)
model4 = didData_year %>% as.data.frame() %>% drop_na("nelda29","log_nlevel", vecControls)
model2 = didData_year %>% as.data.frame() %>% drop_na("freefair","policy_down_level", vecControls)
model5 = didData_year %>% as.data.frame() %>% drop_na("nelda29","policy_down_level", vecControls)
model3 = didData_year %>% as.data.frame() %>% drop_na("freefair","policy_down_u_std", vecControls)
model6 = didData_year %>% as.data.frame() %>% drop_na("nelda29","policy_down_u_std", vecControls)
vecCoefs = c()
vecCE = c() ## How many country-election
for (i in inds){
mod = run_all_models[[i]]
estimate = tidy(mod)%>%filter(term %in% c("treatment","stacktreat"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))}
rows <- tibble::tribble(~term,   ~"(1)",  ~"(2)",  ~"(3)",  ~"(4)",  ~"(5)",  ~"(6)",
"Country-Election FE", "Yes","Yes","Yes","Yes","Yes","Yes",
"Granularity Est./Mean",
as.character(round(vecCoefs[1]/(model1%>% pull(freefair) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[2]/(model2%>% pull(freefair) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[3]/(model3%>% pull(freefair) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[4]/(model4%>% pull(nelda29) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[5]/(model5%>% pull(nelda29) %>% mean() %>% abs()),2)),as.character(round(vecCoefs[6]/(model6%>% pull(nelda29) %>% mean() %>% abs()),2)),
"No. Countries",as.character(length(unique(model1$country_name))),as.character(length(unique(model2$country_name))),as.character(length(unique(model3$country_name))),as.character(length(unique(model4$country_name))),as.character(length(unique(model5$country_name))),as.character(length(unique(model6$country_name))),
"No. Country-Elections", vecCE[1], vecCE[2], vecCE[3],  vecCE[4], vecCE[5], vecCE[6])
attr(rows, 'position') <- c(3, 4, 5, 6, 7, 8)
modelsummary(run_all_models[inds],
col.names = c("","(1)","(2)","(3)","(4)","(5)","(6)"),
fmt = "%.3f",
estimate = "{estimate}{stars}",
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_map = gm,
add_rows = rows,
output = "latex",
coef_map = cm,
notes = "") %>%
save_tt(output = "../Results/Tables/SI-TableJ11-panelB.tex", overwrite = TRUE)
############################################
###########    SI-Table J12      ###########
############################################
inds_vs = which(model_specs_main$outcome %in% c("incumbent_vote_share") &
model_specs_main$treatment %in% c('log_nlevel', 'policy_down_level', 'policy_down_u_std') &
model_specs_main$model_spec_type == "Simple FE")
inds_nelda24 = which(model_specs_nelda24$outcome %in% c("nelda24") &
model_specs_nelda24$treatment %in% c('log_nlevel', 'policy_down_level', 'policy_down_u_std') &
model_specs_nelda24$model_spec_type == "Simple FE")
model1 = didData_year %>% as.data.frame() %>% drop_na('incumbent_vote_share',"log_nlevel", vecControls)
model2 = didData_year %>% as.data.frame() %>% drop_na('incumbent_vote_share',"policy_down_level", vecControls)
model3 = didData_year %>% as.data.frame() %>% drop_na('incumbent_vote_share',"policy_down_u_std", vecControls)
model4 = presData_year %>% as.data.frame() %>% drop_na('nelda24',"log_nlevel", vecControls)
model5 = presData_year %>% as.data.frame() %>% drop_na('nelda24',"policy_down_level", vecControls)
model6 = presData_year %>% as.data.frame() %>% drop_na('nelda24',"policy_down_u_std", vecControls)
vecCoefs = c()
vecCE = c() ## How many country-election
vecPeriod = c() ## How many period
for (i in inds_vs){
mod = run_all_models[[i]]
estimate = broom::tidy(mod)%>%filter(term %in% c("treatment"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))}
for (i in inds_nelda24){
mod = run_all_models_nelda24[[i]]
estimate = broom::tidy(mod)%>%filter(term %in% c("treatment"))%>%pull(estimate)
vecCoefs = c(vecCoefs, abs(estimate[1]))
vecCE = c(vecCE, as.character(round(mod$fixef_sizes[1],0)))}
rows <- tibble::tribble(~term,   ~"(1)",  ~"(2)",  ~"(3)",  ~"(4)",  ~"(5)",  ~"(6)",
"Country-Election FE", "Yes","Yes","Yes","Yes","Yes","Yes",
"Granularity Est./Mean", as.character(round(vecCoefs[1]/(model1%>% pull(incumbent_vote_share) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[2]/(model2%>% pull(incumbent_vote_share) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[3]/(model3%>% pull(incumbent_vote_share) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[4]/(model4%>% pull(nelda24) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[5]/(model5%>% pull(nelda24) %>% mean() %>% abs()),2)),
as.character(round(vecCoefs[6]/(model6%>% pull(nelda24) %>% mean() %>% abs()),2)),
"No. Countries",as.character(length(unique(model1$country_name))),as.character(length(unique(model2$country_name))),as.character(length(unique(model3$country_name))),as.character(length(unique(model4$country_name))),as.character(length(unique(model5$country_name))),as.character(length(unique(model6$country_name))),
"No. Country-Elections", vecCE[1],vecCE[2], vecCE[3],   vecCE[4], vecCE[5], vecCE[6])
attr(rows, 'position') <- c(3, 4, 5, 6, 7, 8)
modelsummary(c(run_all_models[inds_vs],run_all_models_nelda24[inds_nelda24]),
col.names = c("","(1)","(2)","(3)","(4)","(5)","(6)"),
fmt = "%.3f",
estimate = "{estimate}{stars}",
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_map = gm,
add_rows = rows,
output = "latex",coef_map = cm) %>%
save_tt(output = "../Results/Tables/SI-TableJ12.tex", overwrite = TRUE)
###########################################
###########    SI-Figure D2      ##########
###########################################
p1 = didData_year %>% as.data.frame() %>%
filter(election_type=="Presidential", name_english_ == "polling station") |>
ggplot() +
geom_density(aes(x=nlevel)) +
labs(title = "Presidential") +
xlab("") +
theme_classic()
p2 = didData_year %>% as.data.frame() %>%
filter(election_type=="Legislative", name_english_ == "polling station") |>
ggplot() +
geom_density(aes(x=nlevel)) +
labs(title = "Legislative") +
xlab("") +
theme_classic()
p3 = didData_year %>% as.data.frame() %>%
filter(name_english_ == "polling station") |>
ggplot() +
geom_density(aes(x=nlevel)) +
labs(title = "All Elections") +
xlab("") +
theme_classic()
g1 = arrangeGrob(p1, p2, p3, ncol=3)
ggsave(file = "../Results/Figures/SI-FigureD2.pdf", g1,
dpi = 800, width = 8, height = 3)
###########################################
###########    SI-Figure D3      ##########
###########################################
p1 = didData_year %>% as.data.frame() %>%
filter(election_type=="Presidential", unit_level == 1) |>
ggplot() +
geom_density(aes(x=nlevel)) +
labs(title = "Presidential") +
xlab("") +
theme_classic()
p2 = didData_year %>% as.data.frame() %>%
filter(election_type=="Legislative", unit_level == 1) %>%
filter(country_name != "egypt") |>
ggplot() +
geom_density(aes(x=nlevel)) +
labs(title = "Legislative") +
xlab("") +
theme_classic()
p3 = didData_year %>% as.data.frame() %>%
filter(unit_level == 1) %>%
filter(country_name != "egypt") |>
ggplot() +
geom_density(aes(x=nlevel)) +
labs(title = "All Elections") +
xlab("") +
theme_classic()
g2 = arrangeGrob(p1, p2, p3, ncol=3)
ggsave(file = "../Results/Figures/SI-FigureD3.pdf", g2,
dpi = 800, width = 8, height = 3)
